﻿using System;
using System.Data;
using System.Collections.Generic;
using WeiXinPF.Common;
using WeiXinPF.Model;

namespace WeiXinPF.BLL
{
    public class advertisement
    {
        private readonly WeiXinPF.DAL.advertisement dal = new WeiXinPF.DAL.advertisement();

        public advertisement()
        { }

        public void Add(Model.advertisement model)
        {
            dal.Add(model);
        }

        public void Update(Model.advertisement model)
        {
            dal.Update(model);
        }

        public Model.advertisement getModel(int id)
        {
           return dal.getModel(id);
        }

        public bool delete(int id)
        {
            return dal.delete(id);
        }

        public DataSet GetList(int Top, string where,bool isadminedit)
        {
           
            return dal.GetList(Top, where, isadminedit);
        }

        public List<Model.advertisement> GetDefaultModelList()
        {
            return dal.GetDefaultModelList();
        }


        public string GetCateGoryNamebyID(int categoryid)
        {
            string[] ADcategoryid = System.Configuration.ConfigurationSettings.AppSettings["ADcategoryid"].Split('*');
            for (int i = 0; i < ADcategoryid.Length; i++)
            {
                if (ADcategoryid[i] == string.Empty) continue; 
                if (ADcategoryid[i].Split(':')[1] == categoryid.ToString())
                {
                    return ADcategoryid[i].Split(':')[0];
                }
            }
            return "";
        }




        public int GetCateGoryIDbyName(string categoryname)
        {
            string[] ADcategoryid = System.Configuration.ConfigurationSettings.AppSettings["ADcategoryid"].Split('*');
            for (int i = 0; i < ADcategoryid.Length; i++)
            {
                if (ADcategoryid[i] == string.Empty) continue;
                if (ADcategoryid[i].Split(':')[0] == categoryname)
                {
                    return int.Parse(ADcategoryid[i].Split(':')[1]);
                }
            }
            return -1;
        }


        public DataTable GetAllCateGory()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", Type.GetType("System.String"));
            dt.Columns.Add("title", Type.GetType("System.String"));
            string[] ADcategoryid = System.Configuration.ConfigurationSettings.AppSettings["ADcategoryid"].Split('*');
            for (int i = 0; i < ADcategoryid.Length; i++)
            {
                if (ADcategoryid[i] == string.Empty) continue;
                DataRow dr = dt.NewRow();
                dr["ID"] = ADcategoryid[i].Split(':')[1];
                dr["title"] = ADcategoryid[i].Split(':')[0];
                dt.Rows.Add(dr);
            }
            return dt;
        }
    }
}
